package com.company.ljh.easy;
/**
 * 6.输入一个链表的头节点，从尾到头反过来返回每个节点的值（用数组返回）。
 * 输入：head = [1,3,2]
 * 输出：[2,3,1]
 */

import com.company.ljh.utils.ListNode;

/**
 * @description:
 * @projectName:leet_code
 * @see:com.company.ljh.easy
 * @author:ljh
 * @createTime:2022/6/2 16:46
 * @version:1.0
 */
public class 从尾到头打印链表 {
    public int[] reversePrint(ListNode head) {
        ListNode index = head;
        int size = 0;
        while(index != null){
            index = index.next;
            size++;
        }
        int []nums = new int[size];
        while(head != null){
            nums[size-1] = head.val;
            size--;
            head = head.next;
        }
        return nums;
    }
}
